# 记录所有名片字典
card_list = []

# 显示菜单
def show_menu():
    print("*" * 50)
    print("欢迎使用[名片管理系统v1.0]\n ")
    print("1.新增名片\n2.显示全部\n3.搜索名片\n\n0.退出系统")
    print("*" * 50)

# 新增名片
def new_card():
    print("-" * 50)
    print("新增名片")
    name_str = input("请输入姓名： ")
    phone_str = input("请输入电话： ")
    qq_str = input("请输入qq:  ")
    card_dict = {"name":name_str,
                 "phone":phone_str,
                 "qq":qq_str}
    card_list.append(card_dict)
    print("添加 %s 的名片成功" % name_str)

# 显示所有名片
def show_all():
    print("-" * 50)
    print("显示所有名片\n")

    if len(card_list) == 0:
        print("当前没有任何名片记录")
        return
       
    for name in ["姓名","电话","QQ"]:
        print(name, end="\t\t")    
    print("")
    print("=" * 50)
    for card_dict in card_list:
        print("%s\t\t%s\t\t%s\t\t" % (card_dict["name"],
                                    card_dict["phone"],
                                    card_dict["qq"]))
            
# 搜索名片
def search_card():
    print("-" * 50)
    print("搜索名片")
    find_name = input("请输入要搜索的名字： ")
    for card_dict in card_list:
        if card_dict["name"] == find_name:
            print("姓名\t\t电话\t\tQQ\t\t")
            print("=" * 50)
            print("%s\t\t%s\t\t%s\t\t" % (card_dict["name"],
                                    card_dict["phone"],
                                    card_dict["qq"]))
            deal_card(card_dict)
            break
    else:
            print("抱歉没有找到%s" % find_name)

def deal_card(find_dict):
    print(find_dict)
    action_str = input("请选择执行的操作:" \
    "【1】.修改 【2】.删除 【0】.返回上级菜单 :  ")
    if action_str == "1":
        find_dict["name"] = input_card(find_dict["name"],"姓名： ")
        find_dict["phone"] = input_card(find_dict["phone"],"电话： ")
        find_dict["qq"] = input_card(find_dict["qq"],"QQ: ")
        print("修改名片成功")
    elif action_str == "2":
        card_list.remove(find_dict)
        print("删除名片成功")

def input_card(dict_value,tip_message):
    result_str = input(tip_message)
    if len(result_str) > 0:
        return result_str
    else:
        return dict_value